package com.itboye.eweilisten.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Toast;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.app.MyApplication;
import com.itboye.eweilisten.model.TiXingBean;
import com.itboye.eweilisten.util.widget.MyGridView;

/**
 * Created by itboye on 2017/4/8.
 */

public class XuanZeTuPianAdapter extends BaseAdapter {
    TiXingBean bean;
    Context context;

    ImageAdapter adapter;
    String[] name;

    public XuanZeTuPianAdapter(TiXingBean bean, Context context) {
        this.bean = bean;
        this.context = context;
    }

    @Override
    public int getCount() {
        return bean.getList().size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHouder houder = null;
        if (convertView == null) {
            houder = new ViewHouder();
            convertView = LayoutInflater.from(MyApplication.instance).inflate(R.layout.item_shangcheng, null);
            houder.my_gridview = (MyGridView) convertView.findViewById(R.id.my_gridview);
            convertView.setTag(houder);
        } else {
            houder = (ViewHouder) convertView.getTag();
        }
        adapter = new ImageAdapter(bean.getList().get(position).getAnswer(), context);
        houder.my_gridview.setAdapter(adapter);
        houder.my_gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(context, "点击了第"+(position+1)+"张图片", Toast.LENGTH_LONG).show();
                adapter.getPositon(position);
                adapter.notifyDataSetChanged();
            }
        });
        return convertView;
    }

    public class ViewHouder {
        MyGridView my_gridview;
    }
}
